package edu.zju.gis.dldsj.service.impl;

import edu.zju.gis.dldsj.dao.TaskRecordMapper;
import edu.zju.gis.dldsj.entity.Monitor;
import edu.zju.gis.dldsj.entity.TaskRecord;
import edu.zju.gis.dldsj.service.TaskRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yanlo yanlong_lee@qq.com
 * @version 1.0 2018/08/01
 */
@Service
public class TaskRecordServiceImpl implements TaskRecordService {
    @Autowired
    private TaskRecordMapper taskRecordMapper;

    @Override
    public TaskRecord select(String applicationId) {
        return taskRecordMapper.selectByPrimaryKey(applicationId);
    }

    @Override
    public int insert(TaskRecord taskRecord) {
        return taskRecordMapper.insertSelective(taskRecord);
    }

    @Override
    public void update(TaskRecord taskRecord) {
        taskRecordMapper.updateByPrimaryKeyWithBLOBs(taskRecord);
    }

    @Override
    public void delete(String applicationId) {
        taskRecordMapper.deleteByPrimaryKey(applicationId);
    }

    @Override
    public boolean isExist(String applicationId) {
        return taskRecordMapper.selectByPrimaryKey(applicationId) != null;
    }

    @Override
    public List<TaskRecord> getByPage(int offset, int size) {
        return taskRecordMapper.selectByPage(offset, size);
    }

    @Override
    public List<TaskRecord> getByUser(String user) {
        return taskRecordMapper.selectByCreateUser(user);
    }

    @Override
    public List<TaskRecord> getByUserWithState(String user, Monitor.FinalStatus status) {
        return taskRecordMapper.selectByCreateUserWithState(user, status.name());
    }

    @Override
    public List<TaskRecord> getByUserWithoutState(String user, Monitor.FinalStatus status) {
        return taskRecordMapper.selectByCreateUserWithOutState(user, status.name());
    }
}
